#include <bits/stdc++.h>
using namespace std;

int n, m, dx, dy, mx=INT_MIN;
int main() {
    cin >> n >> m;
    int arr[n + 5][m + 5];
    int dir[6][2] = {{1,  0},
                     {1,  1},
                     {1,  -1},
                     {-1, 0},
                     {-1, 1},
                     {-1, -1}};
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
            cin >> arr[i][j];
    for (int i = 1; i <= n; ++i)
        for (int j = 1, sum; j <= m; ++j) {
            sum = arr[i][j];
            for (int k = 0; k < 6; ++k) {
                dx = i + dir[k][0];
                dy = j + dir[k][1];
                if (dx >= 1 and dx <= n and dy >= 1 and dy <= m)
                    sum += arr[dx][dy];
            }
            mx = max(sum, mx);
        }
    cout << mx << endl;
    return 0;
}